package com.choupin.choupin.admin.controller;

import com.choupin.choupin.admin.mapper.ManageLotteryMapper;
import com.choupin.choupin.admin.service.IManageLotteryService;
import com.choupin.choupin.controller.BaseController;
import com.choupin.choupin.entity.JsonResult;
import com.choupin.choupin.entity.Lottery;
import com.choupin.choupin.entity.ShowHotPrize;
import com.choupin.choupin.service.ILotteryPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/index")
public class ManageIndexController extends BaseController {

    @Autowired
    IManageLotteryService manageLotteryService;

    @Autowired
    ILotteryPool iLotteryPool;

//  显示抽奖池
@CrossOrigin
@PostMapping("/show")
public JsonResult<List<Lottery>> showLotterys(@RequestBody Map<String,Object> data){
    JsonResult<List<Lottery>> jsonResult=new JsonResult<>();
    System.out.println("请求来到首页显示抽奖池数据！");
    List<Lottery> lotteries=manageLotteryService.showLotterys((Integer) data.get("currentPage"),(Integer) data.get("pageSize"));
    jsonResult.setState(SUCCESS);
    jsonResult.setData(lotteries);
    return jsonResult;
}

//    显示排行榜
@CrossOrigin
@PostMapping("/showhot")
public JsonResult<List<ShowHotPrize>> showHotPrizeUser(@RequestBody Map<String,Object> data){
    JsonResult<List<ShowHotPrize>> jsonResult=new JsonResult<>();
    System.out.println("来到实时排行："+(String) data.get("name")+","+(Integer) data.get("currentPage")+","+(Integer) data.get("pageSize"));
    List<ShowHotPrize> showHotPrizes=iLotteryPool.showHotPrize((String) data.get("name"),(Integer) data.get("currentPage"),(Integer) data.get("pageSize"));
    jsonResult.setState(SUCCESS);
    jsonResult.setData(showHotPrizes);
    return  jsonResult;
}



}
